package basic;

import basic.DoubleXYZ;
import basic.Transform;
import src.Basic;

public class Plane {

	private double[] norm= new double[3];
	private double dist;

	public Plane(){}

	/**
	 * Costruttore del piano di partizionamento 
	 * per la gerarchia
	 * @param p
	 * @param t
	 */
	public Plane(Plane p, Transform t)
	{
		this.norm = t.operator(p.norm);
		this.dist = p.dist + t.getPosition().dot(this.norm); 	
	}
	public void setValue(double a, double b, double c, double d)
	{
		norm[0]=a; norm[1]=b; norm[2]=c;
		dist = d;
	}

	public void setValue(double[] vector, DoubleXYZ point)
	{
		this.norm=Basic.divNormal(vector);
		this.dist=point.dot(this.norm);
	}

	public double operator(DoubleXYZ p)
	{
		return p.dot(this.norm) - dist;
	}

	/**
	 * Metodo che restituisce l'area del piano
	 * @return
	 */
	public double getDist()
	{
		return this.dist;
	}

	/**
	 * Metodo che restituisce il vettore
	 * normale al piano
	 * @return
	 */
	public double[] getNorm()
	{
		return this.norm;
	}

	public String toString()
	{
		return norm[0] +" "+ norm[1] + " " + norm[2];
	}

}
